<link rel="stylesheet" type="text/css" href="/css/admin/stylesheet.css" />
<link rel="stylesheet" type="text/css" href="/css/admin/editor.css" />
<link rel="stylesheet" type="text/css" href="/js/admin/jquery/ui/themes/ui-lightness/jquery-ui-1.8.9.custom.css" />
<script src="/js/admin/jquery/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="/js/admin/jquery/ui/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="/js/admin/jquery/ui/external/jquery.bgiframe-2.1.2.js" type="text/javascript"></script>
<script src="/js/admin/jquery/tabs.js" type="text/javascript"></script>
<script src="/js/admin/jquery/superfish/js/superfish.js" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="/js/admin/jquery/ui/themes/ui-lightness/jquery.ui.all.css" />
			<form id="content" style="min-width:600px;">
					<input type="hidden" name="i" value="<?php echo $this->i;?>"/>
				    <input type="hidden" name="j" value="<?php echo $this->j;?>"/>
				    	
					<div class="edit_image">
				    	<img src="<?php echo $this->data['src'];?>" id="preview" class="image" onclick="image_upload('image', 'preview');" />
				    	<input type="hidden" name="data[src]" value="<?php echo $this->data['src'];?>" id="image" />
				    	<div class="gi">
				    		Alt : <input type="text" name="data[alt]" value="<?php echo $this->data['alt'];?>"/><br/><br/>
				    		Width : <input onkeypress="return numbersonly(this, event);" maxlength="4" type="text" name="data[width]" id="width" value="<?php echo $this->data['width'];?>"/><br/><br/>
				    		Height : <input onkeypress="return numbersonly(this, event);" maxlength="4" type="text" name="data[height]" id="height" value="<?php echo $this->data['height'];?>"/><br/><br/>
				    		Hspace : <input onkeypress="return numbersonly(this, event);" maxlength="4" type="text" name="data[hspace]" value="<?php echo $this->data['hspace'];?>"/><br/><br/>
				    		Vspace : <input onkeypress="return numbersonly(this, event);" maxlength="4" type="text" name="data[vspace]" value="<?php echo $this->data['vspace'];?>"/><br/><br/>
				    	</div>
				    	<div class="gi">
				    		Border : <input onkeypress="return numbersonly(this, event);" maxlength="4" type="text" name="data[border]" value="<?php echo $this->data['border'];?>"/><br/><br/>
				    		Align : 
				    			<select class="select_image" name="data[align]">
				    				 <option value="0" <?php if($this->data['align'] == 0){?>selected="selected"<?php }?>> &lt;not set&gt;</option>
									 <option value="1" <?php if($this->data['align'] == 1){?>selected="selected"<?php }?>> Left</option>
									 <option value="2" <?php if($this->data['align'] == 2){?>selected="selected"<?php }?>> Right</option>
									 <option value="3" <?php if($this->data['align'] == 3){?>selected="selected"<?php }?>> Top</option>
									 <option value="4" <?php if($this->data['align'] == 4){?>selected="selected"<?php }?>> Text Top</option>
									 <option value="5" <?php if($this->data['align'] == 5){?>selected="selected"<?php }?>> Middle</option>
									 <option value="6" <?php if($this->data['align'] == 6){?>selected="selected"<?php }?>> Abs Middle</option>
									 <option value="7" <?php if($this->data['align'] == 7){?>selected="selected"<?php }?>> Bottom</option>
									 <option value="8" <?php if($this->data['align'] == 8){?>selected="selected"<?php }?>> Abs Bottom</option>
									 <option value="9" <?php if($this->data['align'] == 9){?>selected="selected"<?php }?>> Baseline</option>	
				    			 </select><br/><br/>
				    		Url : <span style="font-weight: normal;">http://</span><input style="width:142px;" type="text" name="data[url]" value="<?php echo $this->data['url'];?>"/><br/><br/>
				    		Target : 
				    			<select class="select_image" name="data[target]">
				    				 <option value="0" <?php if($this->data['target'] == 0){?>selected="selected"<?php }?>> &lt;not set&gt;</option>
									 <option value="1" <?php if($this->data['target'] == 1){?>selected="selected"<?php }?>> New Window (_blank)</option>
									 <option value="2" <?php if($this->data['target'] == 2){?>selected="selected"<?php }?>> Topmost Window (_top)</option>
									 <option value="3" <?php if($this->data['target'] == 3){?>selected="selected"<?php }?>> Same Window (_self)</option>
									 <option value="4" <?php if($this->data['target'] == 4){?>selected="selected"<?php }?>> Parent Window (_parent)</option>
				    			 </select><br/><br/>
				    	</div>
			    	</div>
			</form>
<div style="clear:both;	float:left;	width:100%;">
	<input type="button" style="float: right; margin: 10px; width: 60px;height: 30px; color:white; border: none; background-image: url('/images/btn_short.png');" value="Delete" onclick = "delete_image('<?php echo $this->i;?>','<?php echo $this->j;?>');">
	<input type="button" style="float: right; margin: 10px; width: 60px;height: 30px; color:white; border: none; background-image: url('/images/btn_short.png');" value="Save" onclick = "save();">
</div>

<script type="text/javascript">
function save()
{ 
	var _data =$('#content').serialize();
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{	
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			window.parent.$.prettyPhoto.close();
			window.top.location.reload();
		}	
	};
	var url = "/admin/editor/saveblock?type=2&"+_data;
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}

function delete_image(i,j)
{ 
	if(!window.confirm('Bạn có chắc muốn xóa block này không ?'))
		return false;

	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{	
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			window.parent.$.prettyPhoto.close();
			window.top.location.reload();
		}	
	};
	var url = "/admin/editor/deleteimageblock?i="+i+"&j="+j;
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}
</script>   

<script type="text/javascript"><!--
function image_upload(field, preview) {
	$('#dialog').remove();
	
	$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="/admin/filemanager?field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	
	$('#dialog').dialog({
		title: 'Images Manager',
		close: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$('#' + preview).replaceWith('<img src="' +$('#' + field).attr('value') + '" alt="" id="' + preview + '" class="image" onclick="image_upload(\'' + field + '\', \'' + preview + '\');" />');

				var pic_real_width, pic_real_height;
				$("<img/>") // Make in memory copy of image to avoid css issues
				    .attr("src", $('#' + field).attr('value'))
				    .load(function() {
				        pic_real_width = this.width;   // Note: $(this).width() will not
				        pic_real_height = this.height; // work for in memory images.
				        $('#width').val(pic_real_width);
						$('#height').val(pic_real_height);
				    });
			}
		},	
		bgiframe: false,
		width: 600,
		height: 400,
		resizable: false,
		modal: false
	});
};
//--></script>

<script type="text/javascript">
			<!--
			function numbersonly(myfield, e)
			{
			var key;
			var keychar;
			if (window.event)
			key = window.event.keyCode;
			else if (e)
			key = e.which;
			else
			return true;
			keychar = String.fromCharCode(key);
			// control keys
			if ((key==null) || (key==0) || (key==8) ||
			(key==9) || (key==27) || (key==13))
			return true;
			// numbers
			else if ((("0123456789").indexOf(keychar) > -1))
			return true;
			// decimal point jump
			else
			return false;
			}
			//-->
</script>  